package com.seanliao.nav.common.response;


import com.seanliao.nav.common.enums.ResultCodeEnum;

/**
 * 返回构造器
 *
 * @author Sean_Liao
 */
public class ResultBuilder {
    /**
     * 成功返回体
     */
    public static <T> Result<T> success() {
        return new Result<T>().setCode(ResultCodeEnum.SUCCESS.getCode())
                .setMessage(ResultCodeEnum.SUCCESS.getMessage());
    }

    /**
     * 成功返回体
     */
    public static <T> Result<T> success(T t) {
        return new Result<T>()
                .setCode(ResultCodeEnum.SUCCESS.getCode())
                .setMessage(ResultCodeEnum.SUCCESS.getMessage())
                .setData(t);
    }

    /**
     * 错误返回体
     */
    public static <T> Result<T> fail() {
        return new Result<T>()
                .setCode(ResultCodeEnum.FAIL.getCode())
                .setMessage(ResultCodeEnum.FAIL.getMessage());
    }

    /**
     * 错误返回体 自定义提示信息
     */
    public static <T> Result<T> fail(String message) {
        return new Result<T>()
                .setCode(ResultCodeEnum.FAIL.getCode())
                .setMessage(message);
    }

    /**
     * 错误返回体 自定义返回码和提示信息
     */
    public static <T> Result<T> fail(int code, String message) {
        return new Result<T>()
                .setCode(code)
                .setMessage(message);
    }

}
